//
//  SLChoseStatusTableViewCell.m
//  StarLight
//
//  Created by Duke.wu on 16/5/11.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLChoseStatusTableViewCell.h"

@interface SLChoseStatusTableViewCell ()

@property (nonatomic, strong) UILabel *statusLabel;

@property (nonatomic, strong) UIImageView *statusImageView;

@property (nonatomic, strong) UIButton *selectBtn;

@end



@implementation SLChoseStatusTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    self.isTaped = NO;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [self.contentView addSubview:self.statusImageView];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.selectBtn];
    
    
    [self.statusImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerY.equalTo(self.contentView);
      make.size.mas_equalTo(CGSizeMake(28, 28));
      make.left.equalTo(self.contentView).offset(14);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerY.equalTo(self.contentView);
      make.left.equalTo(self.statusImageView.mas_right).offset(8);
    }];
    
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerY.equalTo(self.contentView);
      make.right.equalTo(self.contentView).offset(-16);
      make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    
    @weakify(self)
    [RACObserve(self, isTaped) subscribeNext:^(NSNumber *x) {
      @strongify(self)
      self.selectBtn.selected = [x boolValue];
    }];
    
    
  }
  return self;
}


#pragma mark - Public Methods

- (void)configWithDictionary:(NSDictionary *)dic{
  self.statusImageView.image = [UIImage imageNamed:dic[@"statusImageView"]];
  self.statusLabel.text = dic[@"statusLabel"];
}




#pragma mark - getter

- (UILabel *)statusLabel{
  if (!_statusLabel) {
    _statusLabel = [UILabel new];
    _statusLabel.font = [UIFont systemFontOfSize:16];
  }
  return _statusLabel;
}

- (UIImageView *)statusImageView{
  if (!_statusImageView) {
    _statusImageView = [UIImageView new];
  }
  return _statusImageView;
}

- (UIButton *)selectBtn{
  if (!_selectBtn) {
    _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_selectBtn setImage:[UIImage imageNamed:@"O"] forState:UIControlStateNormal];
    [_selectBtn setImage:[UIImage imageNamed:@"click_get"] forState:UIControlStateSelected];
  }
  return _selectBtn;
}


@end















